<div class="crumb-wrap">
    <div class="crumb-list"> <i class="icon-font"></i>
        <a href="<?=site_url()?>">首页</a>
        <span class="crumb-step">&gt;</span>
        <span class="crumb-name">项目管理</span>
    </div>
</div>
<div class="search-wrap">
    <div class="search-content">
        <form action="<?=site_url('project/index')?>" method="get">
            <table class="search-tab">
                <tr>
                    <th width="120">选择分类:</th>
                    <td>
                        <select name="search-sort" id="">
                            <option value="">全部</option>
                            <?php foreach($list_sort as $k => $v):?>
                            <?php if(!empty($_GET['search-sort']) && $_GET['search-sort'] == $v['id']):?>
                                <option value="<?=$v['id']?>" selected><?=$v['title']?></option>
                            <?php else:?>
                                <option value="<?=$v['id']?>" ><?=$v['title']?></option>
                            <?php endif;?>
                            <?php endforeach;?>
                        </select>
                    </td>
                    <th width="70">关键字:</th>
                    <td><input class="common-text" placeholder="项目名称" name="keywords" value="<?=empty($_GET['keywords'])? '' : $_GET['keywords'] ?>" id="" type="text"></td>
                    <td><input class="btn btn-primary btn2" value="查询" type="submit"></td>
                </tr>
            </table>
        </form>
    </div>
</div>
<div class="result-wrap">
    <form name="myform" id="myform" method="post">
        <div class="result-title">
            <div class="result-list">
                <a href="<?=site_url('project/create')?>"> <i class="icon-font"></i>
                    新增项目
                </a>
            </div>
        </div>
        <div class="result-content">
            <table class="result-tab" width="100%">
                <tr>
                    <th>排序</th>
                    <th>ID</th>
                    <th>项目分类</th>
                    <th>项目名称</th>
                    <th>更新时间</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>

                <?php foreach($list as $k => $v):?>
                <tr>
                    <td>
                        <input class="common-input sort-input" value="<?=$v['sort']?>" type="text" readonly="readonly" onclick="set_sort(<?=$v['id']?>,<?=$v['sort']?>)">
                    </td>
                    <td><?=$v['id']?></td>
                    <?php if(empty($v['_sort']['title'])):?>
                        <td>其他分类</td>
                    <?php else:?>
                        <td><?=$v['_sort']['title']?></td>
                    <?php endif;?>
                    <td>
                        <a href="javascript:;" title="<?=$v['title']?>" onclick="open_view('<?=site_url('article/show?aid='.$v['article_id'])?>')"><?=$v['title']?></a>
                    </td>
                    <td><?=date('Y-m-d H:i:s',$v['create_time'])?></td>
                    <td><?php
                    if($v['status'] == 1){
                        echo '<span style="color:green">正常</span>';
                    }
                    if($v['status'] == 2){
                        echo '<span>测试</span>';
                    }
                    if($v['status'] == 3){
                        echo '<span style="color:res">关闭</span>';
                    }
                    ?></td>
                    <td>
                        <a class="link-update" href="<?=site_url('project/update?pid='.$v['id'])?>">修改</a>
                        <a class="link-del" href="javascript:;" onclick="delete_project(<?=$v['id']?>)">删除</a>
                    </td>
                </tr>
                <?php endforeach;?>
            </table>
            <div class="list-page"><?=$page?></div>
        </div>
    </form>
</div>

<script type="text/javascript">
    layer.config({
        extend: 'extend/layer.ext.js'
    });
    function open_view(url){
        layer.open({
            type: 2,
            area: ['800px', '600px'],
            fix: false, //不固定
            maxmin: true,
            content: url
        });
    }

    /**
     * 项目删除
     */
    function delete_project(pid){
        layer.confirm('删除之后不可恢复，是否确定？', {
            btn: ['确定','取消'] //按钮
        }, function(){
            $.post("<?=site_url('project/delete')?>",{pid:pid},function(data){
                if(data == 1){
                    layer.alert("操作成功！",{
                        icon:1,
                    },function(){
                        location.reload();
                    });
                }else{
                    layer.alert(data,{
                        icon:2,
                    });
                }
            });
        });
    }

    /**
     * 修改项目排序
     */
    function set_sort(pid,val){
        layer.prompt({
            title: '输入数值（数值大的靠前）',
            value:val
        }, function(sort){
            $.post("<?=site_url('project/set_sort')?>",{pid:pid,sort:sort},function(data){
                if(data == 1){
                    layer.alert("操作成功！",{
                        icon:1,
                    },function(){
                        location.reload();
                    });
                }else{
                    layer.alert(data,{
                        icon:2,
                    });
                }
            });
        });
    }
</script>